const SiteInclusion = require("../../model/siteInclusion.model");
const Classify = require("../../model/classify.model");
class SiteInclusionService {
  async getSiteInclusion(args) {
    const { current = 1, pageSize = 10, ...remainingParameters } = args;
    const offset = (current - 1) * pageSize;
    const { rows: list, count: total } = await SiteInclusion.findAndCountAll({
      limit: Number(pageSize),
      offset: offset,
      where: {
        ...remainingParameters,
      },
      include: [
        {
          model: Classify,
          as: "classifyInfo",
          attributes:["id", "title"],
        },
      ],
      order: [["createdAt",'DESC']],
    });
    return {
      current,
      pageSize,
      total,
      list,
    };
  }
  async addSiteInclusion(args) {
    const { id, createdAt, updatedAt, ...remainingParameters } = args;
    const siteInclusion = await SiteInclusion.create(remainingParameters);
    return siteInclusion;
  }

  async updateSiteInclusion(args) {
    const { id, ...remainingParameters } = args;
    const siteInclusion = await SiteInclusion.update(
      {
        ...remainingParameters,
      },
      {
        where: {
          id,
        },
      }
    );
    return siteInclusion;
  }
  async deleteSiteInclusion(args) {
    const { id } = args;
    const siteInclusion = await SiteInclusion.destroy({
      where: {
        id,
      },
    });
    return siteInclusion;
  }
}

module.exports = new SiteInclusionService();
